<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:v-popover="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>桌台类型管理</title>
    <link rel="stylesheet" href="../../../../static/css/element.css" th:href="@{/css/element.css}">
    <link rel="stylesheet" href="../../../../static/css/global.css" th:href="@{/css/global.css}"/>
    <link rel="stylesheet" href="../../../../static/css/main.css" th:href="@{/css/main.css}"/>
    <link rel="stylesheet" href="../../../../static/css/myelement.css" th:href="@{/css/myelement.css}"/>
    <script src="../../../../static/js/vue.js" th:src="@{/js/vue.js}"></script>
    <script src="../../../../static/js/element.js" th:src="@{/js/element.js}"></script>
    <script src="../../../../static/js/jquery.min.js" th:src="@{/js/jquery.min.js}"></script>
    <script src="../../../../static/js/jquery.nestable.js" th:src="@{/js/jquery.nestable.js}"></script>
</head>
<body>
<div id="app">
    <div class="main-content" v-cloak>
        <!-- 页面头部 -->
        <div class="page-header">
            <h1 class="page-title">桌台类型管理</h1>
            <div class="z-pop_question">
                <el-popover
                        ref="popoverq"
                        placement="bottom-start"
                        width="400"
                        trigger="hover">
                    <p class="z-jiao">
                        1. 查看桌台类型
                        2. 桌台类型可以是大包厢，大堂等类型
                        <a href="javascript:;">查看更多帮助</a>
                    </p>
                </el-popover>
                <i v-popover:popoverq class="el-icon-question"></i>
            </div>
            <div class="breadcrumb"><a href="javascript: top.location.reload();">首页</a><span>/</span>桌台<span>/</span>桌台类型管理</div>
        </div><!-- 页面头部 end -->

        <div class="list-content">
            <!--条件筛选-->
            <div class="content_item_filter clearfix" :class="[hasfilterMore?'content_filter_more':'']">

                <div class="filter-btn fr">
                    <el-button type="primary" @click="showDailog">新增桌台分类</el-button>
                </div>
            </div>

            <!--主体表格-->
            <div class="z-tables">
                <el-table ref="multipleTable" :data="typeList" style="width: 100%;">
                    <el-table-column fixed label="序号" type="index" class-name="z-opt_btn"></el-table-column>
                    <el-table-column prop="name" label="桌台类型名称" min-width="120"></el-table-column>
                    <el-table-column prop="createTime" label="创建时间" min-width="180"></el-table-column>
                    <el-table-column fixed="right" label="操作">
                        <template slot-scope="scope">
                            <el-button type="text" @click="editDailog(scope.$index, scope.row)">编辑</el-button>
                            <span class="table-spea-line">|</span>
                            <el-button type="text" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>

            <!--分页-->
            <div class="grid-content">
                <div class="bg-purple-light">
                    <el-pagination
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            :current-page="currentPage"
                            :page-sizes="pageSizeList"
                            :page-size="pageSize"
                            layout="total, sizes, prev, pager, next"
                            :total="totalNum">
                    </el-pagination>
                </div>
            </div>
            <!-- 新增模态框 -->
            <el-dialog :title="openText" :visible.sync="dialogFormVisible">
                <el-form :model="dinnertabletype" :rules="rules" ref="dinnertabletype-form" label-width="100px" class="demo-ruleForm el-input-95">
                    <el-form-item hidden label="ID" prop="uuid">
                        <el-input v-model="dinnertabletype.uuid"></el-input>
                    </el-form-item>
                    <el-form-item label="类型名称" prop="name">
                        <el-input v-model="dinnertabletype.name"></el-input>
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer" id="addDialog" style="display: none">
                    <el-button @click="save" type="primary">确定</el-button>
                    <el-button @click="dislogHide">取消</el-button>
                </div>
                <div slot="footer" class="dialog-footer" id="editDialog" style="display: none">
                    <el-button @click="update" type="primary">确定</el-button>
                    <el-button @click="dislogHide">取消</el-button>
                </div>
            </el-dialog>
        </div>
    </div>
</div>
</body>
<script th:inline="javascript">
    app = new Vue({
        el: "#app",
        data: {
            loading: true,
            openText: "",
            dialogFormVisible: false,
            tableAllCheck: false,  // table 下方批量操作全选
            hasfilterMore: false,  // 列表是否拥有更多筛选条件
            filterMore: false,  // 列表更多筛选条件是否展示
            dialogVisible: false,
            pageSizeList: [5, 10, 20, 50],
            totalNum: 0,
            currentPage: 1, //当前页码数
            pageSize: 10,
            dinnertabletype:{},
            typeList:[],
            // 定义表单字段的校验规则
            rules: {
                name: [
                    {required: true, message: "请输入类型名称", trigger: 'blur'},
                    {min:2, max:20, message: '类型名称2到20个字符', trigger: 'blur'}
                ],
            }
        },
        created: function () {
            queryList();
        },
        methods: {
            dislogHide: function () {
                this.dialogFormVisible = false;
            },
            save: function () {
                var self = this;
                self.$refs['dinnertabletype-form'].validate((valid) => {
                    if (valid) {
                        $.ajax({
                            url: "/vendor/dinnertabletype/add",
                            type: "POST",
                            data: JSON.stringify(self.dinnertabletype),
                            contentType: "application/json;charset=UTF-8",
                            dataType: "json",
                            success: function(data) {
                                if (data && data.returnCode == "1") {
                                    self.$message({
                                        message: '新增桌台类型成功',
                                        type: 'success',
                                        duration: 1000,
                                        customClass: 'message-center',
                                        onClose: function () {
                                            window.location.href = '/vendor/dinnertabletype/tolist';
                                        }
                                    });
                                } else {
                                    self.$message({
                                        message: data.returnNote,
                                        type: 'error',
                                        duration: 2000,
                                        customClass: 'message-center',
                                        onClose: function () {
                                            window.location.href = '/vendor/dinnertabletype/tolist';
                                        }
                                    });
                                }
                            }
                        });
                    }
                });
            },
            update: function () {
                var self = this;
                self.$refs['dinnertabletype-form'].validate((valid) => {
                    if (valid) {
                        $.ajax({
                            url: "/vendor/dinnertabletype/edit",
                            type: "POST",
                            data: JSON.stringify(self.dinnertabletype),
                            contentType: "application/json;charset=UTF-8",
                            dataType: "json",
                            success: function(data) {
                                if (data && data.returnCode == "1") {
                                    self.$message({
                                        message: '编辑桌台类型成功',
                                        type: 'success',
                                        duration: 1000,
                                        customClass: 'message-center',
                                        onClose: function () {
                                            window.location.href = '/vendor/dinnertabletype/tolist';
                                        }
                                    });
                                } else {
                                    self.$message({
                                        message: data.returnNote,
                                        type: 'error',
                                        duration: 2000,
                                        customClass: 'message-center',
                                        onClose: function () {
                                            window.location.href = '/vendor/dinnertabletype/tolist';
                                        }
                                    });
                                }
                            }
                        });
                    }
                });
            },
            handleSizeChange: function (val) {
                this.pageSize = val;
                queryList();
            },
            handleCurrentChange: function (val) {
                this.currentPage = val;
                queryList();
            },
            handleQuery() {
                this.currentPage = 1;
                queryList();
            },
            showDailog: function () {
                this.dialogFormVisible = true;
                this.openText = "新增桌台类型";
                $("#addDialog").css('display','block');
                $("#editDialog").css('display','none');
                this.dinnertabletype.uuid = '';
                this.dinnertabletype.name = '';
            },
            editDailog: function(index,row){
                this.dialogFormVisible = true;
                this.openText = "编辑桌台类型";
                $("#addDialog").css('display','none');
                $("#editDialog").css('display','block');
                this.dinnertabletype = row;
            },
            // 删除
            handleDelete(index, row) {
                let self = this;
                self.$confirm('确认要删除此桌台类型信息?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                }).then(() => {
                    $.ajax({
                        url: "/vendor/dinnertabletype/delete",
                        type: "POST",
                        data: JSON.stringify([row.uuid]),
                        contentType: "application/json;charset=UTF-8",
                        dataType: "json",
                        success: function (data) {
                            if (data && data.returnCode === 1) {
                                self.$message({
                                    message: '删除桌台类型成功',
                                    type: 'success',
                                    customClass: 'message-center',
                                    duration: 1500,
                                });
                                self.handleQuery();
                            } else {
                                self.$message({
                                    message: data.returnNote,
                                    type: 'error',
                                    customClass: 'message-center',
                                    duration: 2000,
                                });
                            }
                        }
                    });
                });
            },
            tableAllCheckFn(rows) {
                if (rows) {
                    rows.forEach(row => {
                        this.$refs.multipleTable.toggleRowSelection(row, this.tableAllCheck)
                    })
                }
            },
            toggleMoreSearch() {
                this.filterMore = !this.filterMore;
            },
        }
    });

    function queryList() {
        app.loading = true;
        let queryMessage = {
            "queryPage": app.currentPage,
            "pageShow": app.pageSize,
            "sortMap": {
                "uuid": "desc"
            }
        };
        $.ajax({
            url: "/vendor/dinnertabletype/list",
            type: "POST",
            data: JSON.stringify(queryMessage),
            contentType: "application/json;charset=UTF-8",
            dataType: "json",
            success: function (data) {
                if (data && data.returnCode === 1) {
                    app.typeList = data.returnMessage;
                    app.totalNum = data.pager.totalNum;
                }
                app.loading = false;
            }
        });
    }
</script>
</html>